package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/6/18 14:56
 */
@Cmd(code = GameProtocol.S_MANOR_HELP_PLAYER, desc = "庄园协助玩家")
public class ManorHelpPlayerCmd extends AbstractCommand {
    private long helperUserId;
    private long helperServerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ManorProto.HelpPlayerReqMsg reqMsg = ManorProto.HelpPlayerReqMsg.parseFrom(packet.getBytes());
        helperUserId = reqMsg.getUserId();
        helperServerId = reqMsg.getServerId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(0 == helperServerId){
            helperServerId = GameServer.getInstance().getServerId();
        }
       ret = UserMgr.manorHelpPlayer(player, helperUserId, helperServerId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ManorProto.HelpPlayerRespMsg.Builder respMsg = ManorProto.HelpPlayerRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_MANOR_HELP_PLAYER, respMsg);
        }
    }
}
